/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------

bool parse_flag(token_identity identity)
{
	bool result = m_cursor->identity == identity;
	if (result)
	{
		m_cursor.advance();
	}
	return result;
}

// ----------------------------------------------------------------------------

bool parse_list(token_identity content, token_identity separator, token_identity terminator, string_list& out)
{
	while (!m_cursor.exhausted())
	{
		if (m_cursor->identity == content)
		{
			out.push_back(m_cursor->content);
		}
		else
		{
			unexpected_token_error(content);
			return false;
		}

		m_cursor.advance();

		if (m_cursor->identity == terminator)
		{
			return true;
		}
		else if (m_cursor->identity == separator)
		{
			m_cursor.advance();
		}
		else
		{
			unexpected_token_error(separator);
			return false;
		}
	}

	throw eof_error();
}

// ----------------------------------------------------------------------------

template <typename NodeT>
boost::shared_ptr<NodeT> parse_with_lexical_cast(void)
{
	typename NodeT::value_type value = boost::lexical_cast<typename NodeT::value_type>(m_cursor->content);
	m_cursor.advance();
	return boost::make_shared<NodeT>(value);
}

// ----------------------------------------------------------------------------
